<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短剧分类展示平台</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }
        
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
      
        
      
        
        .categories {
            flex: 0 0 250px;
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            height: fit-content;
        }
        
        .categories h2 {
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #f0f2f5;
            color: #2c3e50;
        }
        
        .category-list {
            list-style: none;
            display: flex;
        }
        
        .category-item {
            padding: 12px 15px;
            margin-bottom: 10px;
            border-radius: 8px;
            cursor: pointer;
            display: flex;
            align-items: center;
        }
        
        
        .category-item.active {
          background-color: red;
            color: white;
            font-weight: 600;
            box-shadow: 0 4px 10px rgba(79, 172, 254, 0.4);
        }
        
        
        .category-item.active .category-icon {
            background: rgba(255, 255, 255, 0.3);
        }
        
        .dramas {
            background: white;
            border-radius: 12px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        
        .dramas h2 {
            margin-bottom: 20px;
            color: #2c3e50;
        }
        
        .drama-list {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
        }
        
        .drama-card {
              height: 400px;
            flex-basis: 200px;
            flex-grow: 1;
            height: fit-content;
            background: white;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            cursor: pointer;
        }
        
        
        
        .drama-img {
            width: 100%;
            height: 180px;
            object-fit: cover;
            display: block;
        }
        
        .drama-content {
            padding: 15px;
        }
        
        .drama-title {
            font-size: 1.1rem;
            font-weight: 600;
            margin-bottom: 8px;
            color: #2c3e50;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .drama-desc {
            font-size: 0.9rem;
            color: #666;
            margin-bottom: 12px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .drama-meta {
            display: flex;
            justify-content: space-between;
            color: #777;
            font-size: 0.85rem;
        }
        
        .drama-tag {
            background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
            color: white;
            padding: 2px 8px;
            border-radius: 4px;
            font-size: 0.75rem;
            font-weight: bold;
            position: absolute;
            top: 10px;
            right: 10px;
        }
        
        .loading {
            text-align: center;
            padding: 40px;
            font-size: 1.2rem;
            color: #666;
        }
        
        .error {
            text-align: center;
            padding: 40px;
            color: #e74c3c;
            font-size: 1.1rem;
        }
        
        .empty {
            text-align: center;
            padding: 40px;
            color: #7f8c8d;
            font-size: 1.1rem;
        }
        
        .card-header {
            position: relative;
        }
        
        footer {
            text-align: center;
            margin-top: 40px;
            padding: 20px;
            color: #7f8c8d;
            font-size: 0.9rem;
        }
        
    </style>
</head>
<body>
    <div class="container">
        
        <div class="app-container">
            <div class="categories">
                <ul class="category-list" id="categoryList">
                    
                </ul>
            </div>
            
            <div class="dramas">
                <div class="drama-list" id="dramaList">
                
                </div>
            </div>
        </div>
        
     
    </div>

    <script>
      
        const BASE_URL = 'https://playlet.zonelian.com';
        
        const categoryList = document.getElementById('categoryList');
        const dramaList = document.getElementById('dramaList');
        
        let currentCategory = null;
        
        async function fetchCategories() {
            try {
                const response = await axios.get(`${BASE_URL}/api/category/list`, {
                    params: {
                        page: 1,
                        limit: 15,
                        zlsj: 'zlsj'
                    }
                });
                
                if (response.data.code === 200 && response.data.data.data.length > 0) {
                    renderCategories(response.data.data.data);
                    if (response.data.data.data.length > 0) {
                        selectCategory(response.data.data.data[0]);
                    }
                } else {
                    categoryList.innerHTML = '<li class="error">没有获取到分类数据</li>';
                }
            } catch (error) {
                console.error('获取分类数据失败:', error);
                categoryList.innerHTML = '<li class="error">获取分类数据失败，请稍后再试</li>';
            }
        }
        
        function renderCategories(categories) {
            categoryList.innerHTML = '';
            
            categories.forEach(category => {
                const li = document.createElement('li');
                li.className = 'category-item';
                li.dataset.cid = category.cid;
                li.dataset.nameEn = category.name_en;
                
                li.innerHTML = `
                    <span>${category.name}</span>
                `;
                
                li.addEventListener('click', () => selectCategory(category));
                categoryList.appendChild(li);
            });
        }
        
        // 选择分类
        function selectCategory(category) {
            // 更新UI高亮
            const items = document.querySelectorAll('.category-item');
            items.forEach(item => item.classList.remove('active'));
            
            const selectedItem = document.querySelector(`.category-item[data-cid="${category.cid}"]`);
            if (selectedItem) {
                selectedItem.classList.add('active');
            }
            
            currentCategory = category;
            
            fetchDramas(category.name_en);
        }
        
        async function fetchDramas(nameEn) {
            try {
                
                const response = await axios.get(`${BASE_URL}/api/playlet/list`, {
                    params: {
                        name_en: nameEn,
                        page: 1,
                        limit: 15,
                        zlsj: 'zlsj'
                    }
                });
                
                if (response.data.code === 200 && response.data.data.data.length > 0) {
                    renderDramas(response.data.data.data);
                } else {
                    dramaList.innerHTML = '<div class="empty">该分类下暂无短剧</div>';
                }
            } catch (error) {
                console.error('获取短剧列表失败:', error);
                dramaList.innerHTML = '<div class="error">获取短剧列表失败，请稍后再试</div>';
            }
        }
        
        function renderDramas(dramas) {
            dramaList.innerHTML = '';
            
            dramas.forEach(drama => {
                const card = document.createElement('div');
                card.className = 'drama-card';
                
                card.innerHTML = `
                    <div class="card-header">
                        <img src="${drama.img || 'https://via.placeholder.com/300x180?text=No+Image'}" 
                             alt="${drama.title}" class="drama-img">
                        ${drama.tag ? `<span class="drama-tag">${drama.tag}</span>` : ''}
                    </div>
                    <div class="drama-content">
                        <h3 class="drama-title">${drama.title}</h3>
                        <p class="drama-desc">${drama.description || '暂无描述'}</p>
                        <div class="drama-meta">
                            <span>共${drama.episode}集</span>
                            <span>${drama.viewership}万观看</span>
                        </div>
                    </div>
                `;
                
                dramaList.appendChild(card);
            });
        }
        
        document.addEventListener('DOMContentLoaded', fetchCategories);
    </script>
</body>
</html>